package com.yy.micro.magic.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.yy.micro.magic.type.PersistableEnum;


public enum ExceptionCategory implements PersistableEnum<Integer> {
    RUNTIME("Runtime",ExceptionCategory.RUNTIME_CATEGORY,true),
    BUSINESS("business",ExceptionCategory.BUSINESS_CATEGORY,true),
    CUSTOM("custom",ExceptionCategory.CUSTOM_CATEGORY,false),
    NONE("none",ExceptionCategory.NONE_CATEGORY,false),
    ;
    private int code;
    private String name;
    private boolean block;
    public static final int RUNTIME_CATEGORY = 1<<10;
    public static final int BUSINESS_CATEGORY = 1<<9;
    public static final int CUSTOM_CATEGORY = 1<<8;
    public static final int NONE_CATEGORY = 0;
    ExceptionCategory(String name, int code,boolean block){
        this.name = name;
        this.code = code;
        this.block = block;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public boolean isBlock() {
        return block;
    }

    @Override
    @JsonValue
    public Integer value() {
        return getCode();
    }

    @JsonCreator
    public static ExceptionCategory fromPersistableValue(int value){
        return PersistableEnum.valueOf(value, ExceptionCategory.class);
    }


}
